// 加密解密
package utils

import (
	"log"

	"golang.org/x/crypto/bcrypt"
)

// MakeBcrypt 返回[]byt加密后的字符串
func MakeBcrypt(pwd []byte) string {
	hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
	if err != nil {
		log.Println("bcrypt.GenerateFromPassword:", err.Error())
	}
	return string(hash)
}

// CheckBcrypt 验证密码
func CheckBcrypt(pwd []byte, hashedPwd string) bool {
	if err := bcrypt.CompareHashAndPassword([]byte(hashedPwd), pwd); err != nil {
		return false
	}
	return true
}
